import log from '../helpers/logger';
import { createClient } from '@redis/client';

const { REDIS_URL } = process.env;
console.log('REDIS_URL');
console.log(REDIS_URL);
const redisClient = createClient({ url: REDIS_URL });

redisClient.on('connect', () => log.info('[REDIS] is connecting'));
redisClient.on('ready', () => log.info('[REDIS] is ready'));
redisClient.on('end', () => log.info('[REDIS] disconnected'));
redisClient.on('reconnecting', () => log.info('[REDIS] is reconnecting'));
redisClient.on('error', (e) => log.error(e));

(async () => {
    await redisClient.connect();
   
})();

// If the Node process ends, close the Cache connection
process.on('SIGINT', async () => {
    await redisClient.disconnect();
});

export default redisClient;
